package service

import (
	"fmt"
	"gin-chat/entity"
	"gin-chat/models"
	"gin-chat/pkg"
	. "gin-chat/router/pojo"
	"gin-chat/router/request"
)

func ChatRecordPage(params *request.ChatRecordPageRequest) (result []*entity.CChatRecord, code int) {
	mgr := models.CChatRecordMgr()
	result, err := mgr.ChatRecordPage(params)
	if err != nil {
		code = pkg.InvalidParams
		return
	}
	return
}

//聊天记录写入
func ChatRecordSave(message Message) {
	mgr := models.CChatRecordMgr()
	record := entity.CChatRecord{
		Sender:    int(message.Sender),
		Recipient: int(message.Recipient),
		Content:   message.Content,
	}
	if err := mgr.Create(&record).Error; err != nil {
		fmt.Println("ChatRecordSave err:", err)
		//记录日志
		return
	}
	return
}
